import {
  BwComPropSetConstValueComEnum,
  BwCustomComPropDataTypeEnum,
  BwCustomComEmitParamDataTypeEnum,
  BwCustomComSoltTypeEnum,
  BwCustomComSlotParamDataTypeEnum,
} from '../../../render/models'
import type {
  BwCustomComEmitInfoModel,
  BwCustomComSlotInfoModel,
  BwCustomComPropInfoModel,
} from '../../../render/models'

/** 组件属性 */
const comAttrs: Array<BwCustomComPropInfoModel> = [
  {
    key: 'class',
    name: 'classNames',
    isRequire: false,
    defaultValue: undefined,
    dataType: [
      BwCustomComPropDataTypeEnum.string,
      BwCustomComPropDataTypeEnum.array,
    ],
    defaultValueDataType: BwCustomComPropDataTypeEnum.string,
    constValueSetCom: BwComPropSetConstValueComEnum.input,
    constValueSetComProps: null,
    remark: '',
  },
  {
    key: 'accept',
    name: '接受上传的文件类型',
    isRequire: false,
    defaultValue: undefined,
    dataType: [BwCustomComPropDataTypeEnum.string],
    defaultValueDataType: BwCustomComPropDataTypeEnum.string,
    constValueSetCom: BwComPropSetConstValueComEnum.input,
    constValueSetComProps: null,
    remark: '',
  },
  {
    key: 'action',
    name: '上传的地址',
    isRequire: false,
    defaultValue: undefined,
    dataType: [
      BwCustomComPropDataTypeEnum.string,
      BwCustomComPropDataTypeEnum.function,
    ],
    defaultValueDataType: BwCustomComPropDataTypeEnum.string,
    constValueSetCom: BwComPropSetConstValueComEnum.input,
    constValueSetComProps: null,
    remark: '',
  },
  {
    key: 'beforeUpload',
    name: '上传文件之前的钩子',
    isRequire: false,
    defaultValue: undefined,
    dataType: [BwCustomComPropDataTypeEnum.function],
    defaultValueDataType: BwCustomComPropDataTypeEnum.function,
    constValueSetCom: BwComPropSetConstValueComEnum.textarea,
    constValueSetComProps: null,
    remark: '',
  },
  {
    key: 'customRequest',
    name: '通过覆盖默认的上传行为，可以自定义自己的上传实现',
    isRequire: false,
    defaultValue: undefined,
    dataType: [BwCustomComPropDataTypeEnum.function],
    defaultValueDataType: BwCustomComPropDataTypeEnum.function,
    constValueSetCom: BwComPropSetConstValueComEnum.textarea,
    constValueSetComProps: null,
    remark: '',
  },
  {
    key: 'data',
    name: '上传所需参数或返回上传参数的方法',
    isRequire: false,
    defaultValue: undefined,
    dataType: [
      BwCustomComPropDataTypeEnum.object,
      BwCustomComPropDataTypeEnum.function,
    ],
    defaultValueDataType: BwCustomComPropDataTypeEnum.object,
    constValueSetCom: BwComPropSetConstValueComEnum.textarea,
    constValueSetComProps: null,
    remark: '',
  },
  {
    key: 'directory',
    name: '支持上传文件夹',
    isRequire: false,
    defaultValue: 'false',
    dataType: [BwCustomComPropDataTypeEnum.boolean],
    defaultValueDataType: BwCustomComPropDataTypeEnum.boolean,
    constValueSetCom: BwComPropSetConstValueComEnum.switch,
    constValueSetComProps: null,
    remark: '',
  },
  {
    key: 'disabled',
    name: '是否禁用',
    isRequire: false,
    defaultValue: undefined,
    dataType: [BwCustomComPropDataTypeEnum.boolean],
    defaultValueDataType: BwCustomComPropDataTypeEnum.boolean,
    constValueSetCom: BwComPropSetConstValueComEnum.switch,
    constValueSetComProps: null,
    remark: '',
  },
  {
    key: 'fileList',
    name: '已经上传的文件列表（受控）',
    isRequire: false,
    defaultValue: undefined,
    dataType: [BwCustomComPropDataTypeEnum.array],
    defaultValueDataType: BwCustomComPropDataTypeEnum.array,
    constValueSetCom: BwComPropSetConstValueComEnum.textarea,
    constValueSetComProps: null,
    remark: '',
  },
  {
    key: 'headers',
    name: '设置上传的请求头部',
    isRequire: false,
    defaultValue: undefined,
    dataType: [BwCustomComPropDataTypeEnum.object],
    defaultValueDataType: BwCustomComPropDataTypeEnum.object,
    constValueSetCom: BwComPropSetConstValueComEnum.textarea,
    constValueSetComProps: null,
    remark: '',
  },
  {
    key: 'isImageUrl',
    name: '自定义缩略图是否使用 img 标签进行显示',
    isRequire: false,
    defaultValue: undefined,
    dataType: [BwCustomComPropDataTypeEnum.function],
    defaultValueDataType: BwCustomComPropDataTypeEnum.function,
    constValueSetCom: BwComPropSetConstValueComEnum.textarea,
    constValueSetComProps: null,
    remark: '',
  },
  {
    key: 'listType',
    name: '上传列表的内建样式',
    isRequire: false,
    defaultValue: 'text',
    dataType: [BwCustomComPropDataTypeEnum.string],
    defaultValueDataType: BwCustomComPropDataTypeEnum.string,
    constValueSetCom: BwComPropSetConstValueComEnum.select,
    constValueSetComProps: JSON.stringify({
      options: [
        {
          label: '文本',
          value: 'text',
        },
        {
          label: '图片',
          value: 'picture',
        },
        {
          label: '照片墙',
          value: 'picture-card',
        },
      ],
    }),
    remark: '',
  },
  {
    key: 'maxCount',
    name: '限制上传数量。当为 1 时，始终用最新上传的文件代替当前文件',
    isRequire: false,
    defaultValue: undefined,
    dataType: [BwCustomComPropDataTypeEnum.number],
    defaultValueDataType: BwCustomComPropDataTypeEnum.number,
    constValueSetCom: BwComPropSetConstValueComEnum.number,
    constValueSetComProps: null,
    remark: '',
  },
  {
    key: 'method',
    name: '上传请求的 http method',
    isRequire: false,
    defaultValue: 'post',
    dataType: [BwCustomComPropDataTypeEnum.string],
    defaultValueDataType: BwCustomComPropDataTypeEnum.string,
    constValueSetCom: BwComPropSetConstValueComEnum.input,
    constValueSetComProps: null,
    remark: '',
  },
  {
    key: 'multiple',
    name: '是否支持多选文件',
    isRequire: false,
    defaultValue: 'false',
    dataType: [BwCustomComPropDataTypeEnum.boolean],
    defaultValueDataType: BwCustomComPropDataTypeEnum.boolean,
    constValueSetCom: BwComPropSetConstValueComEnum.switch,
    constValueSetComProps: null,
    remark: '',
  },
  {
    key: 'name',
    name: '发到后台的文件参数名',
    isRequire: false,
    defaultValue: 'file',
    dataType: [BwCustomComPropDataTypeEnum.string],
    defaultValueDataType: BwCustomComPropDataTypeEnum.string,
    constValueSetCom: BwComPropSetConstValueComEnum.input,
    constValueSetComProps: null,
    remark: '',
  },
  {
    key: 'openFileDialogOnClick',
    name: '点击打开文件对话框',
    isRequire: false,
    defaultValue: 'true',
    dataType: [BwCustomComPropDataTypeEnum.boolean],
    defaultValueDataType: BwCustomComPropDataTypeEnum.boolean,
    constValueSetCom: BwComPropSetConstValueComEnum.switch,
    constValueSetComProps: null,
    remark: '',
  },
  {
    key: 'previewFile',
    name: '自定义文件预览逻辑',
    isRequire: false,
    defaultValue: undefined,
    dataType: [BwCustomComPropDataTypeEnum.function],
    defaultValueDataType: BwCustomComPropDataTypeEnum.function,
    constValueSetCom: BwComPropSetConstValueComEnum.textarea,
    constValueSetComProps: null,
    remark: '',
  },
  {
    key: 'progress',
    name: '自定义进度条样式',
    isRequire: false,
    defaultValue: JSON.stringify({ strokeWidth: 2, showInfo: false }),
    dataType: [BwCustomComPropDataTypeEnum.object],
    defaultValueDataType: BwCustomComPropDataTypeEnum.object,
    constValueSetCom: BwComPropSetConstValueComEnum.textarea,
    constValueSetComProps: null,
    remark: '',
  },
  {
    key: 'showUploadList',
    name: '是否展示 uploadList',
    isRequire: false,
    defaultValue: 'true',
    dataType: [
      BwCustomComPropDataTypeEnum.boolean,
      BwCustomComPropDataTypeEnum.object,
    ],
    defaultValueDataType: BwCustomComPropDataTypeEnum.boolean,
    constValueSetCom: BwComPropSetConstValueComEnum.switch,
    constValueSetComProps: null,
    remark: '',
  },
  {
    key: 'supportServerRender',
    name: '服务端渲染时需要打开这个',
    isRequire: false,
    defaultValue: 'false',
    dataType: [BwCustomComPropDataTypeEnum.boolean],
    defaultValueDataType: BwCustomComPropDataTypeEnum.boolean,
    constValueSetCom: BwComPropSetConstValueComEnum.switch,
    constValueSetComProps: null,
    remark: '',
  },
  {
    key: 'withCredentials',
    name: '上传请求时是否携带 cookie',
    isRequire: false,
    defaultValue: 'false',
    dataType: [BwCustomComPropDataTypeEnum.boolean],
    defaultValueDataType: BwCustomComPropDataTypeEnum.boolean,
    constValueSetCom: BwComPropSetConstValueComEnum.switch,
    constValueSetComProps: null,
    remark: '',
  },
]

/** 组件事件 */
const comEmits: Array<BwCustomComEmitInfoModel> = [
  {
    key: 'change',
    name: '上传文件改变时的状态',
    params: [
      {
        paramKey: 'file',
        paramName: '当前操作的文件对象',
        paramDataType: BwCustomComEmitParamDataTypeEnum.object,
        remark: '',
      },
      {
        paramKey: 'fileList',
        paramName: '当前的文件列表',
        paramDataType: BwCustomComEmitParamDataTypeEnum.array,
        remark: '',
      },
      {
        paramKey: 'event',
        paramName:
          '上传中的服务端响应内容，包含了上传进度等信息，高级浏览器支持',
        paramDataType: BwCustomComEmitParamDataTypeEnum.object,
        remark: '',
      },
    ],
  },
  {
    key: 'download',
    name: '点击下载文件时的回调，如果没有指定，则默认跳转到文件 url 对应的标签页',
    params: [
      {
        paramKey: 'file',
        paramName: '当前操作的文件对象',
        paramDataType: BwCustomComEmitParamDataTypeEnum.object,
        remark: '',
      },
    ],
  },
  {
    key: 'drop',
    name: '当文件被拖入上传区域时执行的回调功能',
    params: [
      {
        paramKey: 'event',
        paramName: '拖拽的对象',
        paramDataType: BwCustomComEmitParamDataTypeEnum.object,
        remark: '',
      },
    ],
  },
  {
    key: 'preview',
    name: '点击文件链接或预览图标时的回调',
    params: [
      {
        paramKey: 'file',
        paramName: '当前操作的文件对象',
        paramDataType: BwCustomComEmitParamDataTypeEnum.object,
        remark: '',
      },
    ],
  },
  {
    key: 'reject',
    name: '拖拽文件不符合 accept 类型时的回调',
    params: [
      {
        paramKey: 'fileList',
        paramName: '当前的文件列表',
        paramDataType: BwCustomComEmitParamDataTypeEnum.array,
        remark: '',
      },
    ],
  },
  {
    key: 'remove',
    name: '点击移除文件时的回调',
    params: [
      {
        paramKey: 'file',
        paramName: '当前操作的文件对象',
        paramDataType: BwCustomComEmitParamDataTypeEnum.object,
        remark: '',
      },
    ],
  },
]

/** 组件插槽 */
const comSlots: Array<BwCustomComSlotInfoModel> = [
  {
    slotType: BwCustomComSoltTypeEnum.convention,
    conventionSlotInfo: {
      slotCode: 'default',
      slotName: '默认插槽',
      slotParams: [],
    },
  },
  {
    slotType: BwCustomComSoltTypeEnum.convention,
    conventionSlotInfo: {
      slotCode: 'downloadIcon',
      slotName: '自定义下载 icon',
      slotParams: [
        {
          paramKey: 'params',
          paramName: '插槽参数',
          paramDataType: BwCustomComSlotParamDataTypeEnum.object,
          remark: '',
        },
      ],
    },
  },
  {
    slotType: BwCustomComSoltTypeEnum.convention,
    conventionSlotInfo: {
      slotCode: 'iconRender',
      slotName: '自定义显示 icon',
      slotParams: [
        {
          paramKey: 'params',
          paramName: '插槽参数',
          paramDataType: BwCustomComSlotParamDataTypeEnum.object,
          remark: '',
        },
      ],
    },
  },
  {
    slotType: BwCustomComSoltTypeEnum.convention,
    conventionSlotInfo: {
      slotCode: 'itemRender',
      slotName: '自定义上传列表项',
      slotParams: [
        {
          paramKey: 'params',
          paramName: '插槽参数',
          paramDataType: BwCustomComSlotParamDataTypeEnum.object,
          remark: '',
        },
      ],
    },
  },
  {
    slotType: BwCustomComSoltTypeEnum.convention,
    conventionSlotInfo: {
      slotCode: 'previewIcon',
      slotName: '自定义预览 icon',
      slotParams: [
        {
          paramKey: 'params',
          paramName: '插槽参数',
          paramDataType: BwCustomComSlotParamDataTypeEnum.object,
          remark: '',
        },
      ],
    },
  },
  {
    slotType: BwCustomComSoltTypeEnum.convention,
    conventionSlotInfo: {
      slotCode: 'removeIcon',
      slotName: '自定义删除 icon',
      slotParams: [
        {
          paramKey: 'params',
          paramName: '插槽参数',
          paramDataType: BwCustomComSlotParamDataTypeEnum.object,
          remark: '',
        },
      ],
    },
  },
]

export const antUploadInfo = {
  comAttrs,
  comEmits,
  comSlots,
}
